import { Request, Response } from 'express';
import { NextFunction } from 'express-serve-static-core';
import utils from '../utils';

export default function(req: Request, res: Response, next: NextFunction) {
  if (!!res.locals.data) {
    res.locals.data.data = utils.filterData(res.locals.data.data);
    if (!res.locals.data.data) {
      res.locals.data.data = undefined;
    }
    if (!res.locals.data.code) {
      res.locals.data.code = 200;
    }
    if (!res.locals.data.msg) {
      res.locals.data.msg = 'success';
    }
    res.json(res.locals.data);
    return;
  }
  res.json({
    code: 200,
    msg: 'not found data',
    data: undefined,
  });
}
